<?php

App::uses('Controller', 'Controller');

class AppController extends Controller {
    
    public $pageTitle = '';
    
    public $components = array('Session', 'Cookie');
    
    public $paginate = array(
            'limit' => ITEMS_PER_PAGE
    );
    
    public function no_android($referer) {
        $expire = 60*60*24*100;
        $this->Cookie->write(ANDROID_COOKIE_NAME, 1, false, $expire);
        $this->redirect($referer);
    }
    
    public function beforeRender() {
        // load settings
        $this->loadModel('Settings');
        $this->set('Settings', $this->Settings->load());
        
        // page title
        $this->set('title_for_layout', $this->pageTitle);
        
        // set Main Menu
        $menu = array();
        $menu['Ukusi'] = '/ukusi';
        if (! $this->Group) $this->loadModel('Group');
        foreach ($this->Group->getMenu() as $g) {
            $menu[$g['name']] = "/proizvodi/" . urlize($g['name']) . "/" . $g['id'];
        }
        $menu['Cenovnik'] = '/cene';
        $menu['Kontakt'] = '/kontakt';
        $this->set('menu', $menu);
        
        // android notice
        $this->set('dontShowAndroid', $this->Cookie->read(ANDROID_COOKIE_NAME));
    }
    
    public function setFlash($message, $type='error', $timeout=4) {
        $this->Session->setFlash($message, 'flash', array('type'=>$type, 'timeout'=>$timeout));
    }
    
}
